package com.hx.product.controller;

import com.hx.common.annotation.Log;
import com.hx.common.core.controller.BaseController;
import com.hx.common.core.domain.AjaxResult;
import com.hx.common.core.page.TableDataInfo;
import com.hx.common.enums.BusinessType;

import com.hx.common.utils.poi.ExcelUtil;
import com.hx.product.domain.AttrValue;
import com.hx.product.service.IAttrValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 商品属性与属性值关联Controller
 * 
 * @author Chicken Brother
 * @date 2023-05-18
 */
@RestController
@RequestMapping("/product/AttrValue")
public class AttrValueController extends BaseController
{
    @Autowired
    private IAttrValueService attrValueService;

    /**
     * 查询商品属性与属性值关联列表
     */
    @PreAuthorize("@ss.hasPermi('product:AttrValue:list')")
    @GetMapping("/list")
    public TableDataInfo list(AttrValue attrValue)
    {
        startPage();
        List<AttrValue> list = attrValueService.selectAttrValueList(attrValue);
        return getDataTable(list);
    }

    /**
     * 导出商品属性与属性值关联列表
     */
    @PreAuthorize("@ss.hasPermi('product:AttrValue:export')")
    @Log(title = "商品属性与属性值关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AttrValue attrValue)
    {
        List<AttrValue> list = attrValueService.selectAttrValueList(attrValue);
        ExcelUtil<AttrValue> util = new ExcelUtil<AttrValue>(AttrValue.class);
        util.exportExcel(response, list, "商品属性与属性值关联数据");
    }

    /**
     * 获取商品属性与属性值关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:AttrValue:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(attrValueService.selectAttrValueById(id));
    }

    /**
     * 新增商品属性与属性值关联
     */
    @PreAuthorize("@ss.hasPermi('product:AttrValue:add')")
    @Log(title = "商品属性与属性值关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AttrValue attrValue)
    {
        return toAjax(attrValueService.insertAttrValue(attrValue));
    }

    /**
     * 修改商品属性与属性值关联
     */
    @PreAuthorize("@ss.hasPermi('product:AttrValue:edit')")
    @Log(title = "商品属性与属性值关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AttrValue attrValue)
    {
        return toAjax(attrValueService.updateAttrValue(attrValue));
    }

    /**
     * 删除商品属性与属性值关联
     */
    @PreAuthorize("@ss.hasPermi('product:AttrValue:remove')")
    @Log(title = "商品属性与属性值关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(attrValueService.deleteAttrValueByIds(ids));
    }
}
